import { useUserStore } from "@/stores";

export function useInviteMember() {
  const { state: showInvite, on: openInvite } = useSwitch(false)
  const inviteIsPending = ref<boolean>(false)
  const userStore = useUserStore()
  const inviteInfo = computed(() => userStore.userInfo)
  useEffectScope(() => {
    watch(showInvite, () => {
      if (showInvite.value) {
        refresh()
      }
    }, {
      once: true
    })
  })
  async function refresh() {
    inviteIsPending.value = true
    await userStore.getUserInfo()
    inviteIsPending.value = false
  }
  return {
    showInvite,
    openInvite,
    inviteInfo,
    inviteIsPending
  }
}